package testHutools.testHttpUtil;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import org.junit.Test;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author keyer
 * @Name : hutools.httpUtil.WebsocketTest
 * @Description : 描述
 * Created by cyd on 2021-07-16 09:16:48
 */
public class HttpTest {

    @Test
    public void testContactUrl(){
        String requestUrl = StrUtil.concat(true, "http://", "127.0.0.1:9999", "/preset/info");
        HttpRequest httpRequest = HttpUtil.createGet(requestUrl);
        System.out.println(requestUrl);
    }

    /**
     * 测试向网络调试助手发送数据
     */
    @Test
    public void testSend() throws UnknownHostException {
        // 通过这个就可以得到主机的IP，这个ip是我们的服务器端：192.168.19.1
        System.out.println(InetAddress.getLocalHost());
        String url = "192.168.19.1:10000";
        Apple apple = new Apple("red", 10.0d);
        HttpUtil.post(url, JSONUtil.toJsonStr(apple), 1000);
    }

    /**
     * 测试向springboot的web项目发送数据
     */
    @Test
    public void test() {
        Apple apple = new Apple("red", 10.0d);
        String result = HttpUtil.post("http://localhost:9000/test/apple/sendApple", JSONUtil.toJsonStr(apple),
                5000);
        System.out.println(result);
    }
}
